<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>form表单</title>
		<link rel="stylesheet" href="/adminSite/css/X-ui.css" />
		<link rel="stylesheet" href="/adminSite/css/article-xq.css" />
		<!--[if lt IE 9]>
			<script type="text/javascript" src="/adminSite/js/html5.js"></script>
		<![endif]-->
		<style>
			.form-select{margin-left:-1px;}
			.textarea{margin-top:-1px;}
			img{
		 		width:100%;
		 	}
			.img-box{
				width:200px;
				height:200px;
				overflow:hidden;
				margin-left:20px;
			}
			#upimg{
				margin-top:163px;
				margin-left:20px;
			}
		</style>
	</head>
	<body>
		<ol class="breadcrumb-nav">
			<li>
				<a href="/admin">主页</a>
			</li>
			<li>
				<a href="/admin/article">文章管理</a>
			</li>
			<li>
				添加文章
			</li>
		</ol>
		<form class="x-ui-form form pd-40 mt-10">
			<!--缩略图-->
			<div class="row cl">
				<label class="col-2 form-label">缩略图</label>
				<div class="col-10 cl">
					<div class="img-box border f-l">
						<img src="" id="img">
					</div>
					<input type="hidden" id="img-src" required name="imgSrc" />
					<div id="upimg" class="btn btn-default f-l">上传图片</div>
				</div>
			</div>
			<!--标题-->
			<div class="row cl">
				<label class="form-label col-2">
					标题
				</label>
				<div class="col-10">
					<input type="text" name="title" required class="input-text"/>
				</div>
			</div>
			<!--文章栏目-->
			<div class="row cl">
				<label class="form-label col-2">栏目</label>
				<div class="col-10">
					<div class="form-select" style="width:200px">
						<select required name="column">
							<% if(column){%>
								<% column.forEach(function(data){ %>
									<option value="<%= data._id %>"><%= data.name %></option>
								<% }) %>
							<% } %>
						</select>
					</div>
				</div>
			</div>
			<!--热门推荐-->
			<div class="row cl">
				<label class="form-label col-2">热门推荐</label>
				<div class="col-10">
					<div class="form-select" style="width:200px">
						<select required name="Popular">
							<option value="1">是</option>
							<option value="0" selected>否</option>
						</select>
					</div>
				</div>
			</div>
			<!--关键词-->
			<div class="row cl">
				<label class="form-label col-12 text-l">关键词</label>
				<div class="col-12" id="content">
					<input class="input-text" name="keywords" required placeholder="关键词" />
				</div>
			</div>
			<!--简介-->
			<div class="row cl">
				<label class="form-label col-12 text-l">文章简介</label>
				<div class="col-12" id="content">
					<textarea class="textarea" name="briefing" required placeholder="文章简介"></textarea>
				</div>
			</div>
			<!--文章内容-->
			<div class="row cl">
				<label class="form-label col-12 text-l">文章内容</label>
				<div class="col-12" id="content">
					<script id="editor" type="text/plain" style="width:100%;height:500px;"></script>
					<span class="form-tips">文章内容</span>
				</div>
			</div>
			<!--来源-->
			<div class="row cl">
				<label class="form-label col-2">来源</label>
				<div class="col-10">
					<input type="text" value="原创" name="source" required required class="input-text"/>
				</div>
			</div>
			<!--作者-->
			<div class="row cl">
				<label class="form-label col-2">作者</label>
				<div class="col-10">
					<input type="text" name="author" value="小缘" required required class="input-text"/>
				</div>
			</div>
			<!--收藏-->
			<div class="row cl">
				<label class="form-label col-2">收藏数</label>
				<div class="col-10">
					<input type="text" name="colTion" class="input-text"/>
				</div>
			</div>
			<!--点赞-->
			<div class="row cl">
				<label class="form-label col-2">点赞数</label>
				<div class="col-10">
					<input type="text" name="like" class="input-text"/>
				</div>
			</div>
			<div class="row">
				<!--按钮-->
				<div class="btn btn-submit" id="submit">提交</div>
			</div>
		</form>
		<script type="text/javascript" src="/adminSite/js/jquery-1.11.0.js" ></script>
		<!--弹窗-->
		<script type="text/javascript" src="/adminSite/js/extend/X-ui-modal/js/X-ui-modal.js" ></script>
		<script type="text/javascript" src="/adminSite/js/H-ui-form.js" ></script>
		<script type="text/javascript" src="/adminSite/js/extend/uploadfile.js" ></script>
    	<script type="text/javascript" charset="utf-8" src="/ueditor/ueditor.config.js"></script>
    	<script type="text/javascript" charset="utf-8" src="/ueditor/ueditor.all.min.js"> </script>
    	<script type="text/javascript" charset="utf-8" src="/ueditor/lang/zh-cn/zh-cn.js"> </script>
		<script>
			var ue = UE.getEditor('editor');
			$(function(){
				var form = new XuiForm();
				form.checkbox();
				//select
				form.select();
				form.verification(".form" , "#submit" , {
					title : {
						max : 50,
						min : 5
					},
					source : {
						max : 8,
						min : 1
					},
					author : {
						max : 8,
						min : 1
					}
				},{
					title : {
						empty : "请输入标题",
						min : "标题最少5个字",
						max : "标题最多50个字",
					},
					source : {
						empty : "请输入文章来源",
						min : "来源最少2个字",
						max : "来源最多8个字",
					},
					author : {
						empty : "请输入作者",
						min : "作者最少2个字",
						max : "作者多8个字",
					},
					imgSrc : {
						empty : "请上传缩略图"
					},
					keywords : {
						empty : "请输入关键词"
					}
				}, function(data){
					data["content"] = ue.getContent()
					$.post("/admin/addArticle" , data , function(data){
						if(data.state == "ok"){
							XuiModal().msg("发布成功!" , {icon : 4} , function(){
								//window.location.href = "/admin/article";
							})
						}else{
							XuiModal().msg(data.message , {icon : 2});
						};
					},"JSON")
				});
				//图片上传
				uploadfile.upload({
					fileBtn : "#upimg",
					url : "/uploadfile",
					type : "banner"
				} , function(data){
					$("#img-src").val(data.url);
					$("#img").attr("src" , data.url);
				});
			})
		</script>
	</body>
</html>
